package org.simple.framework.service.step;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import com.simple.framework.infrastructure.pojo.Decider;
import com.simple.framework.infrastructure.pojo.Step;
import com.simple.framework.infrastructure.pojo.StepTask;
import com.simple.framework.infrastructure.pojo.Tasklet;

public class StepService {

	@Autowired
	private ApplicationContext applicationContext;

	public StepTask getStepBean(String beanName) {
		StepTask stepTask = null;

		Object object = applicationContext.getBean(beanName);

		if (object instanceof Tasklet) {
			stepTask = (Tasklet) object;
		} else if (object instanceof Decider) {
			stepTask = (Decider) object;
		} else {
			throw new RuntimeException("暂不支持该类型step");
		}

		return stepTask;
	}

	// 后续可做成缓存
	public Step getStepByStepId(String stepId) {
		// 通过数据库查询出配置的Step
		return null;

	}
}
